<?php
namespace app\api\model;

use think\Model;
use think\Db;

class Force extends Model
{   
   public function getUserForceInfo($user_id){
      //消费记录
      $use_info = Db::name('charge_log')->where('user_id',$user_id)->where('is_pay',1)->field('sum(duration) as total_time,max(duration) as max_time')->find();
   
      $use_total_time = $use_info['total_time'] ? ceil($use_info['total_time']/60) : 0;
      $use_max_time   = $use_info['max_time']   ? ceil($use_info['max_time']/60)   : 0;
      
      $force_info['force_rank']  = 1001;
      $force_info['force_total'] = $use_total_time;
      $force_info['force_best']  = $use_max_time;
      $force_info['update_time'] = time();
      
      if(!Db::name('force_statistics')->where('user_id',$user_id)->find()){
        $force_info['user_id']     = $user_id;
        $force_info['create_time'] = time();

        Db::name('force_statistics')->insert($force_info);
      }else{
        Db::name('force_statistics')->where('user_id',$user_id)->update($force_info);
      }

      return $force_info;
   }



   // //获取用户的战力信息
   // public function getUserForceInfo($user_id){
   //    return Db::name('force_statistics')->where('user_id',$user_id)->field('force_rank,force_total,force_best')->find();
   // }
}